import openai

# 定义工具列表
TOOLS = [
    {
        "name": "calculator",
        "description": "Perform mathematical operations like addition, subtraction, multiplication, division.",
        "parameters": [
            {"name": "parameter1", "type": "number", "description": "First number in the operation"},
            {"name": "parameter2", "type": "number", "description": "Second number in the operation"},
            {"name": "operator", "type": "string", "description": "The operation to perform: 'addition', 'subtraction', 'multiplication', 'division'"}
            ]
    },
    {
        "name": "translator",
        "description": "Translate text from one language to another.",
        "parameters": [
            {"name": "text", "type": "string", "description": "Text to translate"},
            {"name": "from_language", "type": "string", "description": "Source language code (e.g., 'en')"},
            {"name": "to_language", "type": "string", "description": "Target language code (e.g., 'es')"}
            ]
    }
]

# 用户输入
user_input = "帮我计算一下90乘以22"

# 调用 OpenAI GPT 模型（或者类似模型）
response = openai.ChatCompletion.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "你是一个助手，可以根据用户需求调用工具并返回需要的参数。以下是工具列表：" + str(TOOLS)},
        {"role": "user", "content": user_input}
    ],
    functions=TOOLS,  # 把工具信息传递给模型
)

# 输出语言模型决策
print(response)